<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<meta name="apple-mobile-web-app-capable" content="yes"><!--删除默认的苹果工具栏和菜单栏-->
		<meta name="apple-mobile-web-app-status-bar-style" content="black" /><!--状态栏显示为黑色-->
		<meta name="format-detection" content="telephone=no" /><!--电话号码不被显示为拨号连接-->
		<title>融资融券交易终端</title>
		<link rel="stylesheet" href="<?php echo STATIC_SERVER; ?>/mobile/layer/layer.css" id="layui_layer_layercss"/>
		<link rel="stylesheet" href="<?php echo STATIC_SERVER; ?>/mobile/css/weui.css" />
		<link rel="stylesheet" href="<?php echo STATIC_SERVER; ?>/mobile/css/style.css" />
		<script src="<?php echo STATIC_SERVER; ?>/mobile/js/jquery-1.12.1.min.js"></script>
		<script src="<?php echo STATIC_SERVER; ?>/mobile/layer/layer.js"></script>
	</head>
	<body>
		<div class="xinsu-section">
			<div class="xinsu-cross">
				<ul class="xinsu-cross-title">
					<li <?php if ($common_info['action'] == 'index') { ?>class="xinsu-current"<?php } ?>><a href="/stock">持仓单</a></li>
					<li <?php if ($common_info['action'] == 'trust') { ?>class="xinsu-current"<?php } ?>><a href="/stock/trust">委托单</a></li>
					<li <?php if ($common_info['action'] == 'delivery') { ?>class="xinsu-current"<?php } ?>><a href="/stock/delivery">交割单</a></li>
					<div class="xinsu-clear"></div>
				</ul>
				<div class="xinsu-cross-con" id="xinsu-stock-list">
					<div class="xinsu-cross-search">
						<form class="xinsu-form" method="get">
							<input id="begin_time" class="xinsu-input" type="text" readonly name="begin_time" placeholder="开始日期" data-lcalendar="2011-01-1,<?php echo date('Y-m-d'); ?>" value="<?php if (0 != $begin_time) {  echo $begin_time;  } ?>"/>
							<span>--</span>
							<input id="end_time"  class="xinsu-input01" type="text" readonly name="end_time" placeholder="结束日期" data-lcalendar="2011-01-1,<?php echo date('Y-m-d'); ?>" value="<?php if (0 != $begin_time) {  echo $end_time;  } ?>"/>
							<button class="xinsu-btn">查询</button>
						</form>
					</div>
					
					<?php if (empty($list) == false) { ?>
					<?php foreach ($list as $val) { ?>
					<div class="xinsu-cross-list">
						<div class="xinsu-cross-list01">
							<div class="xinsu-cross-list-number">
								<p>编号：<?php echo $val['id']; ?></p>
							</div>
							<div class="xinsu-cross-list-time">
								<p>建仓时间：<?php echo date("Y-m-d H:i:s", $val['bull_time']); ?></p>
								<p>平仓时间：<?php echo date("Y-m-d H:i:s", $val['sell_time']); ?></p>
							</div>
							<div class="xinsu-clear"></div>
						</div>
						<div class="xinsu-cross-list02">
							<div>
								<p>股票名称：<?php echo $val['stock_name']; ?></p>
								<p>数量：<?php echo $val['sell_num']; ?>丨<?php if ($val['sell_type'] == 1) { ?><span class="xinsu-color-red">融资↑</span><?php } else { ?><span class="xinsu-color-green">融券↓</span><?php } ?></p>
								<div class="xinsu-clear"></div>
							</div>
							<ul>
								<li>
									<i>入价</i>
									<span class="xinsu-color-red"><?php echo $val['bull_price']; ?></span>
								</li>
								<li>
									<i>出价</i>
									<span class="xinsu-color-green"><?php echo $val['sell_price']; ?></span>
								</li>
								<li>
									<i>盈亏</i>
									<?php if ($val['total_gain'] > 0) { ?>
									<span class="xinsu-color-red"><?php echo $val['total_gain']; ?></span>
									<?php } else { ?>
									<span class="xinsu-color-green"><?php echo $val['total_gain']; ?></span>
									<?php } ?>
								</li>
								<div class="xinsu-clear"></div>
							</ul>
							<div class="xinsu-clear"></div>
						</div>
						<div class="xinsu-cross-list03">
							<p>手续费：-<?php echo $val['cost']; ?></p>
							<p>留仓天/费：-<?php echo $val['save_money']; ?>/<?php echo $val['save_day']; ?>天</p>
							<div class="xinsu-clear"></div>
						</div>
						<div class="xinsu-cross-list03">
							<p>管理费：-<?php echo $val['manage_money']; ?></p>
							<p>印花税：-<?php echo $val['stamp_money']; ?></p>
							<div class="xinsu-clear"></div>
						</div>
					</div>
					<?php } ?>
					<?php } ?>
				</div>
			</div>
		</div>
		<link rel="stylesheet" href="<?php echo STATIC_SERVER; ?>/mobile/css/lCalendar.css" />
		<script src="<?php echo STATIC_SERVER; ?>/mobile/js/lCalendar.js"></script>
		
		<script>
			<?php if ($common_info['action'] == 'delivery') { ?>
			//日期选择控件
			var calendar = new lCalendar();
			calendar.init({
				'trigger': '#begin_time',
				'type': 'date'
			});
			//日期选择控件
			var calendar = new lCalendar();
			calendar.init({
				'trigger': '#end_time',
				'type': 'date'
			});
			var url = "/stock/<?php echo $common_info['action']; ?>/<?php echo $begin_time; ?>/<?php echo $end_time; ?>/";
			<?php } else { ?>
			var url = "/stock/<?php echo $common_info['action']; ?>/";
			<?php } ?>
			//自动加载
			var p = 2;
			var tmp = 0;
			
			$(window).scroll(function() {
				var scrollTop = $(this).scrollTop();
				var scrollHeight = $(document).height();
				var windowHeight = $(this).height();
				if (scrollTop + windowHeight == scrollHeight) {
					if (tmp != p) {
						//防止重复执行
						tmp = p;
						http_request_post(url + p, {}, function(result){
							if (result.status == 1 && result.data != "") {
								var html = "";
								$.each(result.data, function(key, val){	
									//股票类型
									if (val.sell_type == 1) {
										var bull_type = '<span class="xinsu-color-red">融资↑</span>';
									} else {
										var bull_type = '<span class="xinsu-color-green">融券↓</span>';
									}
									
									//盈亏
									if (val.total_gain > 0) {
										var total_gain = '<span class="xinsu-color-red">'+val.total_gain+'</span>';
									} else {
										var total_gain = '<span class="xinsu-color-green">'+val.total_gain+'</span>';
									}
									
									html += '<div class="xinsu-cross-list"><div class="xinsu-cross-list01"><div class="xinsu-cross-list-number"><p>编号：'+val.id+'</p></div><div class="xinsu-cross-list-time"><p>建仓时间：'+val.b_time+'</p><p>平仓时间：'+val.s_time+'</p></div><div class="xinsu-clear"></div></div><div class="xinsu-cross-list02"><div>	<p>股票名称：'+val.stock_name+'</p>	<p>数量：'+val.sell_num+'丨'+bull_type+'</p><div class="xinsu-clear"></div></div><ul><li><i>入价</i><span class="xinsu-color-red">'+val.bull_price+'</span>	</li><li><i>出价</i><span class="xinsu-color-green">'+val.sell_price+'</span></li><li><i>盈亏</i>'+total_gain+'</li><div class="xinsu-clear"></div></ul><div class="xinsu-clear"></div></div><div class="xinsu-cross-list03"><p>手续费：-'+val.cost+'</p><p>留仓天/费：-'+val.save_money+'/'+val.save_day+'天</p><div class="xinsu-clear"></div></div><div class="xinsu-cross-list03"><p>管理费：-'+val.manage_money+'</p><p>印花税：-'+val.stamp_money+'</p><div class="xinsu-clear"></div></div></div>';
								})
								$("#xinsu-stock-list").append(html);
								p ++;
							}
						});
					}
				}
			});
			
		</script>
		
		<div class="weui-tabbar xinsu-tabbar">
		    <a href="/stock/bull" class="weui-tabbar__item <?php if ($common_info['action'] == 'bull') { ?>xinsu-current<?php } ?>">
			    <div class="weui-tabbar__icon">
			        <i class="xinsu-icon-font xinsu-icon-deal"></i>
			    </div>
		      	<p class="weui-tabbar__label">交易</p>
		    </a>
		    <a href="/stock/index" class="weui-tabbar__item <?php if ($common_info['action'] != 'bull' && $common_info['controller'] == 'stock') { ?>xinsu-current<?php } ?>">
			    <div class="weui-tabbar__icon">
			        <i class="xinsu-icon-font xinsu-icon-search"></i>
			    </div>
			    <p class="weui-tabbar__label">查询</p>
		    </a>
		    <a href="/user/asset" class="weui-tabbar__item <?php if ($common_info['action'] == 'asset' || $common_info['controller'] == 'atm') { ?>xinsu-current<?php } ?>">
		      	<div class="weui-tabbar__icon">
		        	<i class="xinsu-icon-font xinsu-icon-asset"></i>
		      	</div>
		      	<p class="weui-tabbar__label">资产</p>
		    </a>
		    <a href="/" class="weui-tabbar__item <?php if (($common_info['action'] != 'asset' && $common_info['controller'] == 'user') || $common_info['controller'] == 'index') { ?>xinsu-current<?php } ?>">
		      	<div class="weui-tabbar__icon">
		        	<i class="xinsu-icon-font xinsu-icon-user"></i>
		      	</div>
		      	<p class="weui-tabbar__label">我的</p>
		    </a>
		</div>
	</body>
	<script>
		//底部导航隐藏
		var original = document.documentElement.clientHeight;
		window.addEventListener("resize", function() {
			var resizeHeight = document.documentElement.clientHeight;
			if(resizeHeight != original) {
				$('.xinsu-tabbar').hide()
			} else {
				$('.xinsu-tabbar').show()
			}
		});
		var token = "<?php echo $token; ?>";
		//退出登录
		function logout() {
			layer.confirm('您确定要退出？', {icon: 3}, function () {
				stock = system_info = -1
				var url = "/user/logout";
				layer.closeAll();
				http_request_post(url, null, function(res) {
					layer.msg(res.msg, {time: 800}, function () {
						//跳转到登录页面
						location.href = "/user/login";
					});
				});
			});
		}
		
		//提交表单
        var sub = 0;
		$("form").submit(function () {
			//判断提交方式：get-搜索专用，post-保存专用
			var method = $(this).attr("method");
			if (method == "post") {
				//保存专用
				var rmsg = "";
				var data = $(this).serialize();
				if ("<?php echo $common_info['action']; ?>" == "bull") {
					var msg = "您是否确定以上交易？";
					var bull_type = $("input[name='bull_type']:checked").val();
					var price_type = $("input[name='price_type']:checked").val();
					
					//股票类型
					if (bull_type == 1) {
						rmsg += "融资";
					} else {
						rmsg += "融券";
					}
					
					//交易类型
					if (price_type == 0) {
						rmsg += "市价";
					} else {
						rmsg += "限价";
					}
					rmsg += "委托处理成功！";
				} else {
					var msg = "您是否确执行该操作？";
				}
				data += '&token='+token;
				layer.confirm(msg, {icon: 3}, function () {
                    sub += 1;
					layer.closeAll();
                    if (sub == 1) {
                        http_request_post("", data, function (result) {
                            if (rmsg == "") {
                                layer.msg(result.msg, {time:800}, function (){
                                    if (result.data != "") {
                                        location.href = result.data;
                                    } else {
                                        location.reload();
                                    }
                                });
                            } else {
                                layer.alert(rmsg, {icon:1, closeBtn:0}, function(){
                                    if (result.data != "") {
                                        location.href = result.data;
                                    } else {
                                        location.reload();
                                    }
                                });
                            }
                        });
                    }
				});
				return false;
			} else {
				//搜索专用
				var data = $(this).serializeArray();
				var	url = "/<?php echo $common_info['controller']; ?>/<?php echo $common_info['action']; ?>";
				$.each(data, function(key, val) {
					if (val.value == "") {
						url += "/0";
					} else {
						url += "/" + val.value;
					}
				});
				location.href = url;
				return false;
			}
		})
		
		//通用post请求
		function http_request_post(url, data, callback) {
			if (url != "") {
				url = url;
			}
			$.ajax({
				type : 'post',  
				url : url,
				dataType : 'json',
				data : data,
				success : function(repones) {
					if (repones.status == 1) {
						if (typeof callback === "function") {
							callback(repones);
							return false;
						} else {
							layer.msg('请求加载数据失败，请重新加载');
						}
					} else if (repones.status == 2) {
						stock = system_info = -1
						layer.msg(repones.msg, {time:800}, function() {
							location.href = "/user/login";
						});
						return false;
					} else if (repones.status == 0) {
						token = repones.token;
						layer.msg(repones.msg);
						stock = system_info = -1
						return false;
					} else {
						layer.msg(repones.msg);
						stock = system_info = -1
						return false;
					}
				},
				error : function () {
					layer.load(1, {shade: [0.1,'#fff'], time:500}, function(){
						location.reload();
					});
					return false;
				}
			});
			return false;
		}
	</script>
</html>